#ifndef CORE_DATA_H
#define CORE_DATA_H

#include <pthread.h>

#define MAX_ID 5000000

#define MODE_DEFAULT 1
#define MODE_NOTHING 64

#define MAKER_NAME_MAX 64

struct packet_tag {
	unsigned int protocol;
	char maker[MAKER_NAME_MAX];

	struct packet_tag *next;
};

struct core_data {
	pthread_mutex_t lock;	
	unsigned long id;
	int ref;

	int useless;
	
	struct core_data *prev;
	struct core_data *next;

	void *data;
	unsigned short ipsize;
	unsigned short rawsize;

	struct packet_tag *packet_tag_head;
};

struct core_data_queue {
	pthread_mutex_t lock;
	unsigned long next_id;

	unsigned long max_id;
	unsigned int mode;

	unsigned long freed;
	int dont_free;

	struct core_data *core_data_head;
	struct core_data *core_data_tail;
	unsigned long count;
};

extern struct core_data_queue *core_data_queue_create(void);
extern int add_core_data(struct core_data_queue *core_data_queue, void *data, unsigned short ipsize, unsigned short rawsize);
extern void core_data_free(struct core_data *core_data);
/* 
 * Who calld this function should already get all locks,
 * core_data_queue->core_data_tail->prev is not NULL,
 * and should be sure thar core_data_queue is not NULL. 
 *  */
extern void remove_core_data_at_tail(struct core_data_queue *core_data_queue);

#endif
